package com.zretc.file.controller;

import com.zretc.api.pojo.filesAndFriendModule.dto.QueryFileListDTO;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import com.zretc.file.service.FileControlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Slf4j
public class FileControlController {
    @Autowired
    private FileControlService fileControlService;


    @PostMapping("/upload")
    public RespResult upload(@RequestParam("file") MultipartFile file) {

        return fileControlService.upload(file);
    }
    @GetMapping("/downloadjianli")
    public RespResult downloadJianli(String url) {
        return fileControlService.downloadjianli(url);
    }

    /**
     * 上传文件
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_file")
    public RespResult uploadFile(MultipartFile multipartFile) {
        return fileControlService.uploadFile(multipartFile);
    }


    /**
     * 下载文件
     *
     * @param fileUUID
     * @return
     */
    @GetMapping("/{fileUUID}")
    public RespResult downloadFile(@PathVariable("fileUUID") String fileUUID) {
        return fileControlService.downloadFile(fileUUID);
    }

    /**
     * 文件分页查询
     *
     * @param
     * @return
     */
    @GetMapping("/list")
    public RespResult fileList(Integer pageNum, Integer pageSize,String typename,String keyword) {
        //log.info("文件分页查询:{}", queryFileListDTO);
        return R.success( fileControlService.fileList(pageNum,pageSize,typename,keyword));

    }


    /**
     * 删除文件
     * @param fileUUID
     */
//    @DeleteMapping
//    public RespResult deleteFriend(@RequestParam String fileUUID){
//        log.info("文件删除：{}", fileUUID);
//        fileControlService.delete(fileUUID);
//        return RespResult.success();
//    }
}
